package com.yl.ydk.ui.fragment

import android.os.Bundle
import android.view.View
import androidx.recyclerview.widget.GridLayoutManager
import com.yl.ydk.R
import com.yl.ydk.base.BaseFragment
import com.yl.ydk.bean.HealthtestQuestionBean
import com.yl.ydk.ui.activity.HealthtestQuestionActivity
import com.yl.ydk.ui.adapter.OptionAdapter
import kotlinx.android.synthetic.main.fragment_healthy_question.*

class HealthtestQuestionFragment : BaseFragment() {

    private var data: HealthtestQuestionBean.Item? = null

    companion object {
        fun getInstance(data: HealthtestQuestionBean.Item?): HealthtestQuestionFragment {
            val sf = HealthtestQuestionFragment()
            sf.data = data
            return sf
        }
    }

    override fun attachView() {

    }

    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)

        tvName.text = data?.title
        val adapter = OptionAdapter(data?.option?.toMutableList())
        val manager = GridLayoutManager(activity,2)
        rvOption.adapter = adapter
        rvOption.layoutManager = manager

        adapter.onListItemClick(object :OptionAdapter.onListItemClick{
            override fun onListItemClick(item: HealthtestQuestionBean.Option?) {
                HealthtestQuestionActivity.healthtestQuestionActivity?.let {
                    item?.score?.let { score -> it.addScore(score) }
                    it.downFragment()
                }
            }
        })
    }

    override fun getLayoutResId(): Int = R.layout.fragment_healthy_question


}